﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <#include "../common/header.ftl">
</head>
<body>

<div class="container-fluid" style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-lg-2">
            <#assign menu="role">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-lg-10">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">角色编辑</h1>
                </div>
            </div>
            <div class="row col-lg-10">
                <form class="form-horizontal" action="/role/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" value="${(entity.id)!}" name="id">
                    <div class="form-group" >
                        <label class="col-lg-2 control-label">角色名称：</label>
                        <div class="col-lg-4">
                        <input type="text" class="form-control" name="name" value="${(entity.name)!}" placeholder="请输入角色名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-2 control-label">角色编码：</label>
                        <div class="col-lg-4">
                        <input type="text" class="form-control" name="sn" value="${(entity.sn)!}" placeholder="请输入角色编码">
                        </div>
                    </div>
                    <div class="form-group" id="role">
                        <div class="row" style="margin-top: 10px">
                            <div class="col-lg-3 col-lg-offset-1">
                                <div>
                                    <label class="control-label">系统权限：</label>
                                </div>
                                <select multiple class="form-control allPermissions" size="20">
                                    <#--系统中拥有的所有权限-->
                                    <#list (permissions)! as per>
                                        <option value="${(per.id)!}">${(per.name)!}</option>
                                    </#list>
                                </select>
                            </div>
                            <div class="col-lg-1" style="margin-top: 60px;" align="center">
                                <div >
                                    <a type="button" class="btn btn-info  "  style="margin-top: 10px"
                                       onclick="moveSelected('allPermissions', 'selfPermissions')">&nbsp;&gt;&nbsp;</a>
                                    <br>
                                    <a type="button" class="btn btn-info " style="margin-top: 10px"
                                       onclick="moveSelected('selfPermissions', 'allPermissions')">&nbsp;&lt;&nbsp;</a>
                                    <br>
                                    <a type="button" class="btn btn-info " style="margin-top: 10px"
                                       onclick="moveAll('allPermissions', 'selfPermissions')">&gt;&gt;</a>
                                    <br>
                                    <a type="button" class="btn btn-info " style="margin-top: 10px"
                                       onclick="moveAll('selfPermissions', 'allPermissions')">&lt;&lt;</a>
                                </div>
                            </div>
                            <div class="col-lg-3">
                                <div>
                                    <label class="control-label">授予权限：</label>
                                </div>
                                <select multiple class="form-control selfPermissions" size="20" name="ids">
                                    <#--回显当前角色拥有的权限-->
                                    <#list (entity.getPermissions())! as per>
                                        <option value="${(per.id)!}">${(per.name)!}</option>
                                    </#list>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-lg-offset-1 col-lg-6">
                            <button id="btn_submit" type="button" class="btn btn-success">
                                <span class="glyphicon glyphicon-saved"></span> 保存
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>

    // 移动所有权限选项
    function moveAll(srcId,targId) {
        $("."+srcId+" option").appendTo("."+targId);
    }

    //移动选中的权限选项
    function moveSelected(srcId,targId) {
        $("."+srcId+" option:selected").appendTo("."+targId);
    }

    $(function(){
    //  提交表单
        $("#btn_submit").click(function () {
            $(".selfPermissions option").prop("selected",true);
            $("#editForm").submit();
        });

        $.each($(".selfPermissions option"),function (index,ele) {
            $(".allPermissions option[value='"+ele.value+"']").remove();
        });


    });
</script>
</body>
</html>